package com.yanqu.road.server.gameplayer.module.player;

import com.yanqu.road.entity.config.goods.GoodsBagInfo;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.pb.common.CommonProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.manger.system.CommonMgr;
import com.yanqu.road.server.pb.CommonPb;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

public class CommonModule extends GeneralModule {
    public CommonModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return false;
    }

    @Override
    public boolean saveData() {
        return false;
    }

    @Override
    public void loginSendMsg() {
        syncCommonData();
    }

    public void syncCommonData() {
        List<GoodsInfo> goodsInfoList = CommonMgr.getGoodsInfoList();
        if (goodsInfoList.size() > 0) {
            List<GoodsBagInfo> goodsBagInfoList = CommonMgr.getClientGoodsBagInfoList();
            CommonProto.GoodsListMsg.Builder listMsg = CommonPb.parseGoodsListMsg(goodsInfoList, player.getLanguage(), goodsBagInfoList);
            player.sendPacket(Protocol.U_GOODS_INFO_SYNC, listMsg);
        }
    }
}
